import type {ICustomModalProps, IModalProps} from "@shared/base/open";
import {openModal} from "@shared/base/open";
import ImportDialog from "./import-dialog/index.vue";
import ImportDialogV2 from "./import-dialog-v2/index.vue";
import type {IUploadProps} from "./types";

type ImportDialogProps = { onDownload: () => void } | IUploadProps

/**
 * 打开导入对话框
 * @param uploadProps 上传组件属性
 * @param modalProps 对话框属性
 * @example
 * ```ts
 * openImportDialog({
 *    action: '/api/upload',
 *    accept: '.xls,.xlsx',
 *  },
 *  {
 *    title: '导入身份证',
 *    height: '360px',
 *    onOk: () => {
 *      console.log('导入成功')
 *    }
 *  })
 * ```
 */
// @ts-expect-error
export function openImportDialog(uploadProps: ImportDialogProps = {}, modalProps?: Partial<IModalProps & ICustomModalProps<typeof ImportDialog>>) {
  // @ts-expect-error
  openModal<typeof ImportDialog>(
    ImportDialog,
    uploadProps,
    {
      title: '导入身份证',
      height: 'auto',
      useDefaultButton: true,
      okButtonText: '确定',
      // 关闭防止误触
      closeOnClickModal: false,
      closeOnPressEscape: false,
      bodyPadding: '24px',
      ...modalProps
    }
  )
}

/**
 * 打开导入对话框
 * @param uploadProps 上传组件属性
 * @param modalProps 对话框属性
 * @example
 * ```ts
 * openImportDialogV2({
 *    action: '/api/upload',
 *    accept: '.xls,.xlsx',
 *  },
 *  {
 *    title: '导入身份证',
 *    height: '360px',
 *    onOk: () => {
 *      console.log('导入成功')
 *    }
 *  })
 * ```
 */
// @ts-expect-error
export function openImportDialogV2(uploadProps: ImportDialogProps = {}, modalProps?: Partial<IModalProps & ICustomModalProps<typeof ImportDialog>>) {
  // @ts-expect-error
  openModal<typeof ImportDialog>(
    ImportDialogV2,
    uploadProps,
    {
      title: '导入身份证',
      height: 'auto',
      useDefaultButton: true,
      okButtonText: '确定',
      // 关闭防止误触
      closeOnClickModal: false,
      closeOnPressEscape: false,
      bodyPadding: '24px',
      ...modalProps
    }
  )
}
